package com.dp.demo.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.dp.demo.config.MyNacosProperties;
import com.dp.demo.service.GoodsClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: dupeng
 * @CreateTime: 2024-12-05  18:03
 * @Description: TODO
 */
@RestController
@RequestMapping(value = "/test")
public class TestController {

    @Autowired
    private GoodsClient goodsClient;
    @Autowired
    private MyNacosProperties myNacosProperties;
    @Value("${test.info}")
    private String local;

    @GetMapping("/getTest1")
    @SentinelResource(value = "testResource", blockHandler = "testBlockHandler", blockHandlerClass = TestController.class)
    public String getTest2(Integer id) {
        return goodsClient.getHello();
//        return local + "-" +myNacosProperties.getName() + "-" + myNacosProperties.getAge() + "-" + myNacosProperties.getAddress();
    }

    public static String testBlockHandler(Integer id, BlockException ex) {
        System.out.println("testBlockHandler...");
        return "testBlockHandler... " ;
    }

}
